import axios from 'axios'
import {Message} from "element-ui";

const request = axios.create({
    baseURL : process.env.VUE_APP_BASE_API,
    // baseURL : 'http://127.0.0.1:9090/',
    timeout : 5000
})

request.interceptors.request.use(
    //配置网络请求前置参数
    config =>{

        return config
    },
    error => {
        return Promise.reject(error)
    }
)

request.interceptors.response.use(
    response =>{

        const res = response.data

        if (res.code !== 200){
            Message({
                message: res.message,
                type: 'error',
                duration: 5 * 1000
            })
        }else {
            return res
        }
    },
    error => {
        Message({
            message: error.response.data.message,
            type: 'error',
            duration: 5 * 1000
        })
        return Promise.reject(error)
    }
)

export default request